package com.hotel.project.demo.controller;

import com.hotel.project.demo.domain.HotelCommentEntity;
import com.hotel.project.demo.domain.ResponseBean;
import com.hotel.project.demo.domain.vo.CommentAndAnswerVo;
import com.hotel.project.demo.domain.vo.ImageVo;
import com.hotel.project.demo.service.HotelCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/hotel/comment")
@Api(value = "HotelCommentController", tags = "酒店评论控制器")
public class HotelCommentController extends BaseController<HotelCommentService, HotelCommentEntity>{

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "逻辑删除酒店评论", notes = "根据酒店评论id删除")
    public ResponseBean deleteCommentById(@PathVariable("id") Long id) {
        ResponseBean rb = new ResponseBean();
        boolean flag = service.deleteHotelCommentByCommentId(id);
        if (flag) {
            return rb;
        }
        return errorEdit(rb, 10001l);
    }

    @GetMapping("/list-user")
    @ApiOperation(value = "查询指定用户的评论", notes = "根据用户id查询")
    public ResponseBean getCommentByOrderUserId(Long orderUserId){
        ResponseBean rb = new ResponseBean();
        CommentAndAnswerVo result = service.getCommentByOrderUserId(orderUserId);
        if (result!=null) {
            // 将缩略图内容转换成集合
            if (result.getFirstBigImage() != null) { // 第一张缩略图大图
                if (result.getFirstSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getFirstSmallImage(), result.getFirstBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getFirstSmallImage(), ""));
                }
            }

            if (result.getSecondBigImage() != null) { // 第二张缩略图大图
                if (result.getSecondSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getSecondSmallImage(), result.getSecondBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getSecondSmallImage(), ""));
                }
            }

            if (result.getThirdBigImage() != null) { // 第三张缩略图大图
                if (result.getThirdSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getThirdSmallImage(), result.getThirdBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getThirdSmallImage(), ""));
                }
            }

            if (result.getFourthBigImage() != null) { // 第四张缩略图大图
                if (result.getFourthSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getFourthSmallImage(), result.getFourthBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getFourthSmallImage(), ""));
                }
            }

            if (result.getFifthBigImage() != null) { // 第五张缩略图大图
                if (result.getFifthSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getFifthSmallImage(), result.getFifthBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getFifthSmallImage(), ""));
                }
            }

            if (result.getSixthBigImage() != null) { // 第六张缩略图大图
                if (result.getSixthSmallImage() != null) {
                    result.getImages().add(new ImageVo(result.getSixthSmallImage(), result.getSixthBigImage()));
                }else{
                    result.getImages().add(new ImageVo(result.getSixthSmallImage(), ""));
                }
            }
            rb.setData(result);
            return rb;
        }else{
            return errorEdit(rb, 10002l);
        }


    }

}
